package com.eternal.data.ui;

import android.content.Context;
import android.util.AttributeSet;

import com.eternal.base.concat.TmpHum;
import com.eternal.base.global.BluetoothKey;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Locale;

public class GraphHumBarView extends GraphBarView {
    private DecimalFormat format;

    public GraphHumBarView(Context context) {
        this(context, null);
    }

    public GraphHumBarView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GraphHumBarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        format=new DecimalFormat("#.0");
        format.setRoundingMode(RoundingMode.FLOOR);
    }

    @Override
    String formatMaxMin(int value) {
        if(value== BluetoothKey.EMPTY){
            return "--%";
        }
        return format.format(value/100f)+"%";
    }

    @Override
    TimeValue getItem(int position) {
        TmpHum temp=adapter.getItem(position);
        return new TimeValue(temp.time, temp.hum);
    }

    @Override
    int getMax() {
        return adapter.maxHum;
    }

    @Override
    int getMin() {
        return adapter.minHum;
    }

    @Override
    String formatValue(int value) {
        return String.format(Locale.ENGLISH,"%d%%",(int)Math.floor(value/100f));
    }
}
